#!/bin/bash

# 修复所有API路由中的params.id问题

FILES=(
  "/home/z/my-project/src/app/api/projects/[id]/protection/route.ts"
  "/home/z/my-project/src/app/api/projects/[id]/route.ts"
  "/home/z/my-project/src/app/api/projects/[id]/samples/[sampleId]/route.ts"
  "/home/z/my-project/src/app/api/projects/[id]/samples/route.ts"
  "/home/z/my-project/src/app/api/projects/[id]/status/route.ts"
  "/home/z/my-project/src/app/api/projects/[id]/tasks/route.ts"
  "/home/z/my-project/src/app/api/projects/[id]/team/[memberId]/route.ts"
  "/home/z/my-project/src/app/api/projects/[id]/team/route.ts"
)

for file in "${FILES[@]}"; do
  if [ -f "$file" ]; then
    echo "Fixing $file..."
    # 替换params类型定义
    sed -i 's/{ params }: { params: { id: string } }/{ params }: { params: Promise<{ id: string }> }/g' "$file"
    # 替换params.id的使用
    sed -i 's/params\.id/(await params).id/g' "$file"
    echo "Fixed $file"
  else
    echo "File not found: $file"
  fi
done

echo "All API files fixed!"